package com.ruoyi.find.service;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.input.Prompt;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class AiService {

    private final ChatLanguageModel chatModel;

    // LangChain4j 会自动从 application.yml 读取配置并注入 ChatLanguageModel
    public AiService(ChatLanguageModel chatModel) {
        this.chatModel = chatModel;
    }

    // 同步调用：直接返回 AI 回答
    public String ask(String question) {
        return chatModel.generate(question);
    }

    // 异步调用（可选，适合高并发场景）
    public CompletableFuture<String> askAsync(String question) {
        return CompletableFuture.supplyAsync(() -> chatModel.generate(question));
    }
}